<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('推荐药维护')" />
</head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>
                        <li>
                           商品码：<input type="text" name="goodscode" th:placeholder="商品码"/>
                    </li>
<!--                        <li>
                            拼音码：<input type="text" name="plucode" th:placeholder="条码"/>
                        </li>-->
                        <li>
                            商品名称：<input type="text" name="goodsname" th:placeholder="商品名称"/>
                        </li>
<!--                        <li>
                            客户名称：<input type="text" name="companyName"/>
                        </li>-->
                        <!--  <li>
                              岗位状态：<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
                              <option value="">所有</option>
                              <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                          </select>
                          </li>-->
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>

                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
<!--            <a class="btn btn-success" onclick="$.operate.add()" >
                <i class="fa fa-plus"></i> 新增
            </a>-->
<!--            <a class="btn btn-success" onclick="link()" >
                <i class="fa"></i> 新增药品关系
            </a>-->
<!--            <a class="btn btn-success" onclick="recommend()" >
                <i class="fa"></i> 新增为推荐
            </a>-->
<!--            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:post:edit">
                <i class="fa fa-edit"></i> 修改
            </a>-->
<!--            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:post:remove">
                <i class="fa fa-remove"></i> 删除
            </a>-->
<!--            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:post:export">
                <i class="fa fa-download"></i> 导出
            </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
<!--    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form1">
                <div class="select-list">
                    <ul>
                        <li>
                            药品信息：<input type="text" name="plucode" th:placeholder="店内码或拼音码"/>
                        </li>
                        &lt;!&ndash;                        <li>
                                                    客户名称：<input type="text" name="companyName"/>
                                                </li>&ndash;&gt;
                        &lt;!&ndash;  <li>
                              岗位状态：<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
                              <option value="">所有</option>
                              <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                          </select>
                          </li>&ndash;&gt;
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>-->

        <!--        <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="$.operate.add()" >
                        <i class="fa fa-plus"></i> 新增
                    </a>
                    <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:post:edit">
                        <i class="fa fa-edit"></i> 修改
                    </a>
                    <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:post:remove">
                        <i class="fa fa-remove"></i> 删除
                    </a>
                    <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:post:export">
                        <i class="fa fa-download"></i> 导出
                    </a>
                </div>-->

<!--        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table1"></table>
        </div>-->
    </div>
</div>


<th:block th:include="include :: footer" />
<script th:inline="javascript">
    //  var editFlag = [[${@permission.hasPermi('system:post:edit')}]];
    // var removeFlag = [[${@permission.hasPermi('system:post:remove')}]];
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var prefix = ctx + "baodao/demo01";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
          //  removeUrl: prefix + "/remove",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            /*  sortName: "companyId",*/
            modalName: "药品关系",
            // 测试父子表
            detailView: true,
            // 测试新增 查询条件
           /* queryParams: function(params) {
                var curParams = {
                    // 传递参数查询参数
                    pageSize: params.limit,
                    pageNum: params.offset / params.limit + 1,
                    searchValue: params.search,
                    orderByColumn: params.sort,
                    isAsc: params.order,
                    // 新增 flag 为0 展示全部 药品信息，为1 展示药品关联表中已建立关系的药品列表
                    //   flag:  $("#flag").val()
                    flag: 0
                }
                return curParams;
            },*/
            columns: [
/*                {
                checkbox: true
            },*/
                {
                    field: 'goodscode',
                    title: '商品码'
                },
                {
                    field: 'goodsname',
                    title: '商品名称'
                },
                {
                    field: 'mfrs',
                    title: '生产厂商'
                },
                {
                    field: 'norm',
                    title: '规格'
                },
                {
                    field: 'num1',
                    title: '推荐药'
                },
                {
                    field: 'num2',
                    title: '关联药'
                },
                //注册加载子表的事件。注意下这里的三个参数！

                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                       /* actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.goodscode + '\')"><i class="fa fa-plus"></i>新增</a> ');*/
                     /*   actions.push('<a class="btn btn-success btn-xs ' + "editFlag" + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.goodscode + '\')"><i class="fa fa-edit"></i>编辑</a> ');*/
                        /* actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.postId + '\')"><i class="fa fa-remove"></i>删除</a>');*/
                       // actions.push('<a class="btn btn-danger btn-xs ' + "removeFlag" + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodscode + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-danger btn-xs ' + "removeFlag" + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodscode + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }],
                onExpandRow: function (index, row, $detail) {
                //oInit.InitSubTable(index, row, $detail);
                    console.log("展开子表")
                    console.log("行数据：" + "index:" + index )
                    console.log(row)
                    initSubTable(index,row,$detail)
            }

        };
        $.table.init(options);
    });
</script>

<script>
    // 获得所有选中的数据
    function link() {
        // $.table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        console.log("已选择数据数量：" + rows.length)
        console.log("已选择数据" + rows.toString())
        let id = rows.toString();
        let url = ctx + 'baodao/demo01/add' + '?id=' + id;
        console.log("弹窗 url" + url)
        var result = url.replace(/#/g, '%23');
        $.modal.openTab("新增药品关系",result);
    }
/*    function recommend() {
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        console.log("已选择数据数量：" + rows.length)
        console.log("已选择数据" + rows.toString())
        let id = rows.toString();
        let url = ctx + 'baodao/demo01/edit' + '?id=' + id;
        console.log("弹窗 url" + url)
        var result = url.replace(/#/g, '%23');
        $.modal.openTab("新增为关联",result);
    }*/
    //初始化子表格(无线循环)
    initSubTable = function (index, row, $detail) {

        function queryParams(){
            let tmp = {"goodsCode":row.goodscode};
            return tmp;
        }
        var parentid = row.id;
        var cur_table = $detail.html('<table></table>').find('table');
      //  var cur_table = $detail.html('<table><title>测试</title></table>').find('table');
        $(cur_table).bootstrapTable({
            url: ctx + 'baodao/demo01/queryGoodsLink',
            method: 'post',
            contentType: 'application/x-www-form-urlencoded',
            queryParams:queryParams(),
            //data: {'goodsCode':'401-01-330'},
            ajaxOptions: { id: parentid },
            uniqueId: "id",
            striped: true, //是否显示行间隔色
            pagination: true,//显示分页
            sidePagination: "client",
            pageNumber:1,
            pageSize: 4,
            pageList: [4, 25],
            columns: [
                {
                    field: 'showFlag',
                    title: '关联药品',
                    formatter: function (value) {
                        if(value == '1'){
                            return '推荐药'
                        }else
                        if(value == '2'){
                            return '关联药'
                        }else {
                            return value;
                        }

                    }
                },
                {
                    field: 'goodscode',
                    title: '商品码'
                },
                {
                    field: 'goodsname',
                    title: '商品名称'
                },
                {
                    field: 'mfrs',
                    title: '生产厂商'
                },
                {
                    field: 'norm',
                    title: '规格'
                },
/*                {
                    field: 'plucode',
                    title: '关联药品推荐'
                },*/
/*                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        /!* actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.goodscode + '\')"><i class="fa fa-plus"></i>新增</a> ');*!/
                        /!*   actions.push('<a class="btn btn-success btn-xs ' + "editFlag" + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.goodscode + '\')"><i class="fa fa-edit"></i>编辑</a> ');*!/
                        /!* actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.postId + '\')"><i class="fa fa-remove"></i>删除</a>');*!/
                        /!* actions.push('<a class="btn btn-danger btn-xs ' + "removeFlag" + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodscode + '\')"><i class="fa fa-remove"></i>删除</a>');*!/
                        return actions.join('');
                    }
                }*/
            /*    {
                    field: 'mfrs',
                    title: '生产企业'
                },
                {
                    field: 'norm',
                    title: '包装规则'
                },
                {
                    field: 'plucode',
                    title: '条码'
                },*/
            ],
            //无线循环取子表，直到子表里面没有记录
            onExpandRow: function (index, row, $Subdetail) {
                initSubTable(index, row, $Subdetail);
            }
        });
    };

/*    function(id) {
        table.set();
        $.modal.confirm("确定删除该条" + table.options.modalName + "信息吗？", function() {
            var url = $.common.isEmpty(id) ? table.options.removeUrl : table.options.removeUrl.replace("{id}", id);
            if(table.options.type == table_type.bootstrapTreeTable) {
                $.operate.get(url);
            } else {
                var data = { "ids": id };
                $.operate.submit(url, "post", "json", data);
            }
        });

    },*/


</script>
</body>
</html>